<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta http-equiv="pragram" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <link href="/Public/Home/css/style.css" rel="stylesheet" type="text/css">
    <link href="/Public/Home/css/iconfont.css" rel="stylesheet" type="text/css">
    <script src="/Public/Home/js/jquery-1.11.1.min.js"></script>
    <script src="/Public/Home/js/publicjquery.js"></script>
    <script src="/Public/Home/js/layer/layer.js" ></script>
    <script src="/Public/Home/js/common.js" ></script>
    <script src="/Public/Home/js/ajaxfileupload.js" ></script>
</head>
<style>
    .main {margin: 0;}
    .content {margin: 0;}
    .head-content {padding: 0;}
    span {display:inline-block;padding-left: 10px;}
    *{box-sizing: border-box;-moz-box-sizing: border-box;-webkit-box-sizing: border-box;}
</style>
<body onselectstart="return false">
<div class="main FromUpToDown" style="height: 400px;width:500px;min-width:500px;" >
    <div class="content" style="position: relative" >
        <div class="head-content" style="height: 30px;background-color: #BFD4F0;font-size: 14px">
                <span style="line-height: 30px;">选择号码</span>
                <button onclick="send()" style="float:right;background: #3ece67;height:22px;border:none;padding:0 10px;border-radius: 3px;margin-top: 4px;cursor:pointer;color:#fff;margin-right: 10px;">发送</button>
        </div>
        <div style="height: 220px;overflow-y:auto;" class="table-list">
            <table cellpadding="0" cellspacing="0">
                <thead>
                <tr >
                    <th>序号</th>
                    <th>手机号</th>
                    <th>订单号</th>
                </tr>
                </thead>
                <?php if(is_array($list)): foreach($list as $k=>$vo): ?><tr >
                        <td><?php echo ($k+1); ?> <input checked value="<?php echo ($vo['id']); ?>" type="checkbox"> </td>
                        <td><?php echo ($vo['phone']); ?></td>
                        <td><?php echo ($vo['no']); ?></td>
                    </tr><?php endforeach; endif; ?>
            </table>
        </div>
        <div style="height: 150px">
            <span style="background-color: #BFD4F0;width: 100%;height: 28px;line-height: 28px;padding-left: 10px">短信内容</span>
            <div  style="margin-top:10px" >
               <span style="float: left;padding-right:10px;">选择:</span>
                <select name="template_id" id="template_id" style="height: 26px">
                    <option value="">选择短信内容</option>
                    <?php if(is_array($template)): foreach($template as $key=>$vo): ?><option value="<?php echo ($vo['id']); ?>"><?php echo ($vo['name']); ?></option><?php endforeach; endif; ?>
                </select>
            </div>
            <div style="margin-top:10px">
               <span style="display: inline-block;float: left;padding-right:10px;">内容:</span><textarea  id="template_content" name="" style="width:80%;height:60px;resize:none; "></textarea>
            </div>
        </div>
    </div>
</div>
<script>
    var template_list = <?php echo json_encode($template);?>;
    var template = {};
    if(template_list) {
        for (var i = 0; i < template_list.length; i++) {
            var id = template_list[i].id;
            template[id] = template_list[i].content;
        }
    }

    $("#template_id").change(function(){
        template_id = $(this).val();
        if(!template_id) return;
        template_content = template[template_id];
        $("#template_content").html(template_content);
    });

    function send()
    {
        var ids = [];
        $("input:checkbox:checked").each(function(){
            ids.push($(this).val());
        });
        var template_id = $("select[name='template_id']").val();
        if(!ids){
            layer.msg('请选择要发送的记录!',{time:1000});
            return ;
        }
        if(!template_id){
            layer.msg('请选择短信模板！',{time:1000});
            return ;
        }
        var index = layer.load(0, {shade: false});
        $.post(
                "<?php echo U('SendSms/index');?>",
                {
                  ids:ids,
                  template_id:template_id
                },function(res){
                    layer.close(index);
                    if(res.status == 1){
                        layer.msg(res.info,{time:1000});
                        setTimeout("window.parent.location.reload()",1000);
                    }else{
                        layer.msg(res.info,{time:5000});
                    }
                }
        )
    }

   // console.info(window.parent.location.reload());
</script>
</body>
</html>